#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
typedef long long LL;

int n, m;
int l[N],r[N];
LL need[N],sum[N],p[N];

bool check(int a){
    memset(sum, 0, sizeof(sum));
    for (int i = 1; i <= a; i++){
        sum[l[i]] += p[i];
        sum[r[i] + 1] -= p[i];
    }
    for (int i = 1; i <= n; i++){
        sum[i] = sum[i - 1] + sum[i];
        if (need[i] - sum[i] < 0){
            return false;
        }
    }
    return true;
}

int main(){
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++){
        scanf("%lld", &need[i]);
    }
    for(int i=1;i<=m;i++){
    	scanf("%lld%d%d",&p[i],&l[i],&r[i]);
	} 
    if (check(m)){
        printf("0");
        return 0;
    }
    else printf("-1\n");
    int l = 1, r = m - 1, mid;
    while (l<r){
        mid = (r - l) / 2 + l;
        if (check(mid)){
            l=mid+1;
        }
        else{
            r = mid;
        }
    }
	printf("%d", l);
    return 0;
}
